﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using HotSpot.Util;

namespace HotSpot.Silverlight.Web.WebServices
{
    /// <summary>
    /// Manage HotSpot documents
    /// </summary>
    [WebService(Namespace = "http://hotspot.cloudapp.net/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class HotSpotBlob : System.Web.Services.WebService
    {
        bool Authenticate(string username, string password)
        {
            if (username == "arthur.csertus" && password == "arthur")
                return true;
            else
                return false;
        }

        [WebMethod]
        public void UploadBlob(
            string username,
            string password,
            string blobName,
            byte[] blobData)
        {
            if (!Authenticate(username, password))
                return;

            HotSpotDocument.Upload(blobName, blobData);
        }

        [WebMethod]
        public byte[] DownloadBlob(string blobName)
        {
            return HotSpotDocument.Download(blobName);
        }
    }
}
